package com.sskj.one.http;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.UserInfo;
import com.sskj.one.bean.AccountBean;
import com.sskj.one.bean.AgreeBean;
import com.sskj.one.bean.AssetListBean;
import com.sskj.one.bean.AvailableBean;
import com.sskj.one.bean.BankerInfoBean;
import com.sskj.one.bean.BuyOrderBean;
import com.sskj.one.bean.CompanyBankBean;
import com.sskj.one.bean.DividendListBean;
import com.sskj.one.bean.GongGaoMsgBean;
import com.sskj.one.bean.GonggaoBean;
import com.sskj.one.bean.GouhuiBean;
import com.sskj.one.bean.HistoryBean;
import com.sskj.one.bean.InviteBean;
import com.sskj.one.bean.LastestBean;
import com.sskj.one.bean.LevelBean;
import com.sskj.one.bean.ListHuiBean;
import com.sskj.one.bean.MoneyBean;
import com.sskj.one.bean.MoneyListBean;
import com.sskj.one.bean.MusicBean;
import com.sskj.one.bean.PageBean;
import com.sskj.one.bean.PositionBean;
import com.sskj.one.bean.ProxyBean;
import com.sskj.one.bean.SevenBean;
import com.sskj.one.bean.Stock;
import com.sskj.one.bean.TanChuangBean;
import com.sskj.one.bean.TeamLevelBean;
import com.sskj.one.bean.TongdaoBean;
import com.sskj.one.bean.UpdataBean;
import com.zxy.recovery.tools.RecoveryUtil;

import java.io.File;
import java.util.List;

import dagger.Reusable;
import io.reactivex.Flowable;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {

    public GetRequest<HttpData<List<Stock>>> getStockInfo() {
        return OkGo.<HttpData<List<Stock>>>get(HttpConfig.BASE_URL + HttpConfig.K)
                .params("goodsType", "sec")
                .params("code", "USDCNY");
    }

    /**
     * 发送短信
     * type 都是 3
     *
     * @param mobile
     * @return
     */
    public PostRequest<HttpData<Object>> sendCode(String mobile) {
        return OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.SEND_CODE)
                .params("mobile", mobile)
                .params("type", 3);
    }

    /**
     * 注册
     *
     * @param mobile     手机号
     * @param code       验证码
     * @param pwd        密码
     * @param pwd1       密码1
     * @param inviteCode 邀请码
     * @return
     */
    public PostRequest<HttpData<AccountBean>> register(String mobile, String code, String pwd, String pwd1, String inviteCode) {
        return OkGo.<HttpData<AccountBean>>post(HttpConfig.BASE_URL + HttpConfig.REGISTER)
                .params("mobile", mobile)
                .params("code", code)
                .params("password", pwd)
                .params("repassword", pwd1)
                .params("invitation_code", inviteCode);
    }

    /**
     * 登录
     *
     * @param mobile 手机号
     * @param pwd    登录密码
     * @return
     */
    public PostRequest<HttpData<AccountBean>> login(String mobile, String pwd) {
        return OkGo.<HttpData<AccountBean>>post(HttpConfig.BASE_URL + HttpConfig.LOGIN)
                .params("mobile", mobile)
                .params("password", pwd);
    }

    /**
     * 忘记登录及密码
     *
     * @param mobile 手机号
     * @param code   密码
     * @param pwd    密码
     * @param pwd1   短信验证码
     * @return
     */
    public PostRequest<HttpData> forgetLogin(String mobile, String code, String pwd, String pwd1) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.FORGET_LOGIN)
                .params("mobile", mobile)
                .params("opwd", pwd)
                .params("opwd1", pwd1)
                .params("code", code);
    }

    /**
     * 重置登录密码
     *
     * @param mobile 用户ID
     * @param code   短信验证码
     * @param pwd    密码
     * @param pwd1   密码
     * @return
     */
    public PostRequest<HttpData> resetLogin(String mobile, String code, String pwd, String pwd1) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.RESET_LOGIN)
                .params("account", mobile)
                .params("opwd", pwd)
                .params("opwd1", pwd1)
                .params("code", code);
    }

    /**
     * 设置/充值交易密码
     *
     * @param mobile 用户ID
     * @param code   短信验证码
     * @param pwd    密码
     * @param pwd1   密码
     * @return
     */
    public PostRequest<HttpData> setPayPwd(String mobile, String code, String pwd, String pwd1) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SET_PAY_PWD)
                .params("account", mobile)
                .params("tpwd", pwd)
                .params("tpwd1", pwd1)
                .params("code", code);
    }

    /**
     * 我的推广
     *
     * @return
     */
    public GetRequest<HttpData<InviteBean>> getInvite() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.INVITE);
    }

    /**
     * 获取七级返佣信息
     *
     * @return
     */
    public GetRequest<HttpData<SevenBean>> getSevenLevel() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.SEVEN_LEVEL);
    }

    /**
     * 股池信息
     *
     * @return
     */
    public GetRequest<HttpData<BankerInfoBean>> getBankInfo(int page, int size) {
        return OkGo.<HttpData<BankerInfoBean>>get(HttpConfig.BASE_URL + HttpConfig.BANKER_INFO)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 股权转出（不能输入金额，直接转出全部可用资产）
     *
     * @param pwd 交易密码
     * @return
     */
    public PostRequest<HttpData> transferOut(String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER_OUT)
                .params("tpwd", pwd);
    }

    /**
     * 股权转入
     *
     * @param money 投股金额
     * @param pwd   资金密码
     * @return
     */
    public PostRequest<HttpData> transferIn(String money, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER_IN)
                .params("money", money)
                .params("tpwd", pwd);
    }

    /**
     * 公告列表
     *
     * @param page
     * @param size
     * @return
     */
    public PostRequest<HttpData<List<GonggaoBean>>> getGonggaoList(int page, int size) {
        return OkGo.<HttpData<List<GonggaoBean>>>post(HttpConfig.BASE_URL + HttpConfig.GONGGAO_LIST)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 团队分级、收益
     *
     * @return
     */
    public GetRequest<HttpData<TeamLevelBean>> getTeamLevelInfo() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.TEAM_DENGJI);
    }

    /**
     * 获取对应等级内包含的会员信息
     *
     * @param page
     * @param size
     * @return
     */
    public GetRequest<HttpData<List<LevelBean>>> getLevelList(int page, int size, String level) {
        return OkGo.<HttpData<List<LevelBean>>>get(HttpConfig.BASE_URL + HttpConfig.LEVEL_LIST)
                .params("level", level)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 获取协议文本
     *
     * @param type
     * @return
     */
    public PostRequest<HttpData<AgreeBean>> getAgree(String type) {
        return OkGo.<HttpData<AgreeBean>>post(HttpConfig.BASE_URL + HttpConfig.AGREE)
                .params("inc_type", type);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    public GetRequest<HttpData<UserInfo>> getUserInfo() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.USER_INFO);
    }

    /**
     * 公告详情
     *
     * @param id 公告id
     * @return
     */
    public GetRequest<HttpData<GongGaoMsgBean>> getGongGao(String id) {
        return OkGo.<HttpData<GongGaoMsgBean>>get(HttpConfig.BASE_URL + HttpConfig.NOTICE)
                .params("id", id);
    }

    /**
     * 资产明细
     *
     * @param page
     * @param size
     * @return
     */
    public GetRequest<HttpData<PageBean<AssetListBean>>> getAsssetRecord(int page, int size) {
        return OkGo.<HttpData<PageBean<AssetListBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASSET_RECORD)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 今日分红
     *
     * @param page
     * @return
     */
    public GetRequest<HttpData<List<DividendListBean>>> todayDividendt(int page) {
        return OkGo.<HttpData<List<DividendListBean>>>get(HttpConfig.BASE_URL + HttpConfig.TODAY_DIVIDEND)
                .params("p", page);
    }

    /**
     * 历史分红
     *
     * @param page
     * @return
     */
    public GetRequest<HttpData<List<DividendListBean>>> historicalDividendt(int page) {
        return OkGo.<HttpData<List<DividendListBean>>>get(HttpConfig.BASE_URL + HttpConfig.HISTORY_DIVIDEND)
                .params("p", page);
    }

    /**
     * 佣金天梯、历史佣金
     *
     * @return
     */
    public GetRequest<HttpData<ProxyBean>> getProxyInfo(int p, int size) {
        return OkGo.<HttpData<ProxyBean>>get(HttpConfig.BASE_URL + HttpConfig.PROXY_INFO)
                .params("p", p)
                .params("size", size);
    }

    /**
     * 获取背景音乐
     *
     * @return
     */
    public PostRequest<HttpData<MusicBean>> getMusic() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.MUSIC);
    }

    /**
     * 获取购汇率
     *
     * @return
     */
    public GetRequest<HttpData<MoneyListBean>> getMoneys() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.GET_MONEYS);
    }

    /**
     * 下单
     *
     * @param buyMoney 下单金额
     * @param type     1 买涨 2 买跌
     */
    public PostRequest<HttpData<BuyOrderBean>> buy(String buyMoney, String type) {
        return OkGo.<HttpData<BuyOrderBean>>post(HttpConfig.BASE_URL + HttpConfig.BUY)
                .params("buynum", buyMoney)
                .params("otype", type);
    }

    /**
     * 持仓记录
     *
     * @param page
     * @param size
     * @return
     */
    public GetRequest<HttpData<List<PositionBean>>> getPositionRecord(int page, int size) {
        return OkGo.<HttpData<List<PositionBean>>>get(HttpConfig.BASE_URL + HttpConfig.POSITION_RECORD)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 历史记录
     *
     * @param page
     * @param size
     * @return
     */
    public GetRequest<HttpData<List<HistoryBean>>> getHistoryBean(int page, int size) {
        return OkGo.<HttpData<List<HistoryBean>>>get(HttpConfig.BASE_URL + HttpConfig.HISTORY_RECORD)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 交易查询
     *
     * @param page
     * @param size
     * @return
     */
    public GetRequest<HttpData<List<HistoryBean>>> getHistoryBean(String begin, String end, int page, int size) {
        return OkGo.<HttpData<List<HistoryBean>>>get(HttpConfig.BASE_URL + HttpConfig.HISTORY_RECORD)
                .params("begin_time", begin)
                .params("end_time", end)
                .params("p", page)
                .params("size", size);
    }

    /**
     * 最新盈利
     *
     * @return
     */
    public GetRequest<HttpData<List<LastestBean>>> getNewProfit() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.NEW_PROFIT);
    }

    /**
     * 最新订单
     *
     * @return
     */
    public GetRequest<HttpData<List<LastestBean>>> getNewOrders() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.NEW_ORDERS);
    }

    /**
     * 版本管理
     * type 1 Android 2 ios
     *
     * @param versionCode 当前版本号
     * @return
     */
    public PostRequest<HttpData<UpdataBean>> checkVersion(String versionCode) {
        return OkGo.<HttpData<UpdataBean>>post(HttpConfig.BASE_URL + HttpConfig.CHECK_VERSION)
                .params("version", versionCode)
                .params("type", "1");
    }

    /**
     * 购汇信息
     *
     * @return
     */
    public GetRequest<HttpData<List<String>>> getRechargeInfo() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.RECHARGE_INFO);
    }

    /**
     * 获取可用支付通道
     *
     * @return
     */
    public PostRequest<HttpData<List<TongdaoBean>>> getTongdaos() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.TONGDAO);
    }

    /**
     * 购汇
     *
     * @param gouHuiMOney 充值金额
     * @param tongdao     支付通道
     * @return
     */
    public PostRequest<HttpData<GouhuiBean>> createRechargeOrder(String gouHuiMOney, String tongdao) {
        return OkGo.<HttpData<GouhuiBean>>post(HttpConfig.BASE_URL + HttpConfig.CREATE_RECHARGE)
                .params("money", gouHuiMOney)
                .params("zftd", tongdao);
    }

    /**
     * 用户购汇列表
     *
     * @param p
     * @param size
     * @return
     */
    public GetRequest<HttpData<List<ListHuiBean>>> getGouHuiRecord(int p, int size) {
        return OkGo.<HttpData<List<ListHuiBean>>>get(HttpConfig.BASE_URL + HttpConfig.GOUHUI_RECORD)
                .params("page", p)
                .params("size", size);
    }

    /**
     * 用户结汇列表
     *
     * @param p
     * @param size
     * @return
     */
    public GetRequest<HttpData<List<ListHuiBean>>> getJieHuiRecord(int p, int size) {
        return OkGo.<HttpData<List<ListHuiBean>>>get(HttpConfig.BASE_URL + HttpConfig.JIEHUI_RECORD)
                .params("p", p)
                .params("size", size);
    }

    /**
     * 结汇
     *
     * @param money    结汇金额
     * @param pwd      资金密码
     * @param payway   1：微信 2:支付宝 3：银行卡
     * @param username 姓名
     * @param wechat   微信号
     * @param alipay   支付宝号
     * @param bank     开户行名称
     * @param branch   开户支行名称
     * @param bankCard 银行卡号
     * @return
     */
    public PostRequest<HttpData> gouhui(String money, String pwd, String payway, String username, String wechat, String alipay
            , String bank, String branch, String bankCard) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.GOUHUI)
                .params("money", money)
                .params("tpwd", pwd)
                .params("tj_id", payway)
                .params("wechat_nums", wechat)
                .params("alipay_nums", alipay)
                .params("username", username)
                .params("bank_name", bank)
                .params("bank_sub_name", branch)
                .params("bank_nums", bankCard)
                ;
    }

    /**
     * 弹窗公告
     *
     * @return
     */
    public PostRequest<HttpData<TanChuangBean>> getGonggao() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.TAN_CHUANG);
    }

    /**
     * 修改头像
     *
     * @param upic 头像
     * @return
     */
    public PostRequest<HttpData> changeUpic(String upic) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHANGE_UPIC)
                .params("upic", upic);
    }

    /**
     * 修改昵称
     *
     * @param nickname 昵称
     * @return
     */
    public PostRequest<HttpData> setNickName(String nickname) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CHANGE_NICKNAME)
                .params("nickname", nickname);
    }

    /**
     * 平仓后查询上一个订单
     *
     * @param tran_id 本次订单ID
     * @return
     */
    public GetRequest<HttpData<HistoryBean>> getLastOrder(String tran_id) {
        return OkGo.<HttpData<HistoryBean>>get(HttpConfig.BASE_URL + HttpConfig.LAST_ORDER)
                .params("tran_id", tran_id);
    }

    /**
     * 平仓后查询下一个订单
     *
     * @param tran_id 本次订单ID
     * @return
     */
    public GetRequest<HttpData<HistoryBean>> getNextOrder(String tran_id) {
        return OkGo.<HttpData<HistoryBean>>get(HttpConfig.BASE_URL + HttpConfig.NEXT_ORDER)
                .params("tran_id", tran_id);
    }

    /**
     * 平仓时获取最新订单信息
     *
     * @param hold_no 下单时返回的单号
     * @return
     */
    public GetRequest<HttpData<HistoryBean>> getOrder(String hold_no) {
        return OkGo.<HttpData<HistoryBean>>get(HttpConfig.BASE_URL + HttpConfig.ORDER_MSG)
                .params("tran_no", hold_no);


    }

    /**
     * 绑定支付宝
     *
     * @param name    姓名
     * @param account 支付宝账号
     * @param pwd     资金密码
     * @return
     */
    public PostRequest<HttpData> addAlipay(String name, String account, String pwd, File image) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADD_ALIPAY)
                .params("alipay_username", name)
                .params("alipay_nums", account)
                .params("code", image)
                .params("tpwd", pwd);
    }

    /**
     * 绑定银行卡
     *
     * @param name   姓名
     * @param bank   银行名
     * @param branch 支行名
     * @param card   银行卡号
     * @param pwd    资金密码
     * @return
     */
    public PostRequest<HttpData> addBank(String name, String bank, String bankID, String branch, String card, String pwd) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADD_BANK)
                .params("bank_username", name)
                .params("bank_nums", card)
                .params("bank_name", bank)
                .params("bank_code", bankID)
                .params("bank_sub_name", branch)
                .params("tpwd", pwd);

    }

    /**
     * 用户线下购汇获取平台收款信息
     *
     * @return
     */
    public GetRequest<HttpData<CompanyBankBean>> getShoukuanMsg() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.COMPANY_BANK);
    }

    /**
     * 线下购汇
     *
     * @param gouHuiMOney
     * @param tongdao
     * @param type
     * @param name
     * @param alipay
     * @param bank
     * @param branch
     * @param card
     * @param img
     * @return
     */
    public PostRequest<HttpData> xianxiaGouhui(String gouHuiMOney, String tongdao, String type, String name, String alipay, String bank, String branch, String card, File img) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.CREATE_RECHARGE)
                .params("money", gouHuiMOney)
                .params("zftd", tongdao)
                .params("ptype", type)
                .params("username", name)
                .params("alipay_nums", alipay)
                .params("bank_name", bank)
                .params("bank_branch_name", branch)
                .params("bank_nums", card)
                .params("certificate_img", img);
    }

    /**
     * 获取可领取的分红余额
     *
     * @return
     */
    public GetRequest<HttpData<AvailableBean>> getAvailableFenhong() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.AVAILABLE_FENHONG);
    }

    public PostRequest<HttpData> lingquFenhong() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.LINGQU_FENHONG);
    }
}